package com.bdqn.entity;
import	java.util.Collections;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.StringUtils;


import java.io.Serializable;
import java.util.*;

public class Images implements Serializable {
    private String uuid;

    private String address;

    private String title;

    private String userUuid;

    private  String   imgUrl[];

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createtime;

    private Integer status;

    private String url;

    private static final long serialVersionUID = 1L;
    private  String albumJson ;
    private  String cover ;

    public String getDataDiff() {
        long day = ((System.currentTimeMillis() - getCreatetime().getTime()) / 1000 /60/60 / 24);
        if (day==0){
            return ((System.currentTimeMillis() - getCreatetime().getTime()) / 1000 / 60/60 )+"小时之前";
        }
        return day+"天之前";
    }

    public void setDataDiff(String dataDiff) {
        this.dataDiff = dataDiff;
    }

    private  String dataDiff ;


    public String getCover() {
        if (getUrl()!=null){
            return getImgUrl()[getImgUrl().length-1];
        }
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public String getAlbumJson() {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("title",getTitle());
        map.put("id",getUuid());
        map.put("start",0);
        map.put("data",getTitle());
        String[] urls=getImgUrl();
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        for (String u :urls ){
            Map<String,Object> temp = new HashMap<String,Object>();
            temp.put("alt",getTitle());
            temp.put("pid",System.currentTimeMillis());
            temp.put("src",u);
            temp.put("thumb","");
            list.add(temp);
        }
        map.put("data",list);
        return JSON.toJSONString(map);
    }

    public void setAlbumJson(String albumJson) {
        this.albumJson = albumJson;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid == null ? null : uuid.trim();
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address == null ? null : address.trim();
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title == null ? null : title.trim();
    }

    public String getUserUuid() {
        return userUuid;
    }

    public void setUserUuid(String userUuid) {
        this.userUuid = userUuid == null ? null : userUuid.trim();
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url == null ? null : url.trim();
    }

    public String[] getImgUrl() {
            if (StringUtils.isNotBlank(getUrl())){
                return  getUrl().split(",");
            }
        return imgUrl;
    }

    public void setImgUrl(String[] imgUrl) {
        this.imgUrl = imgUrl;
    }
}